package com.lucien.test;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class homework {
    public static void main(String[] args) {
        JFrame jFrame = new JFrame("单选按钮和复选按钮");
        JPanel jPanel = new JPanel();
        JLabel jLabel1 = new JLabel("你选择了：");
        JLabel jLabel2 = new JLabel("你选择了：");
        JRadioButton [] buttons = new JRadioButton[4];
        JCheckBox [] boxes = new JCheckBox[4];
        ButtonGroup group = new ButtonGroup();
        buttons[0] = new JRadioButton("a");buttons[1] = new JRadioButton("b");
        buttons[2] = new JRadioButton("c");buttons[3] = new JRadioButton("d");
        jFrame.add(buttons[0]);jFrame.add(buttons[1]);
        jFrame.add(buttons[2]);jFrame.add(buttons[3]);
        jPanel.add(jLabel1);
        jPanel.add(jLabel2);
        buttons[0].addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                jLabel1.setText("你选择了：a");
            }
        });
        buttons[1].addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                jLabel1.setText("你选择了：b");
            }
        });
        buttons[2].addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                jLabel1.setText("你选择了：c");
            }
        });
        buttons[3].addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                jLabel1.setText("你选择了：d");
            }
        });



        jFrame.add(jPanel);
        jFrame.setSize(500,400);
        jFrame.setVisible(true);
        jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}
